import Vue from 'vue'
import VueResource from 'vue-resource'
import * as echarts from 'echarts'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'
// 添加事件管理者passive
import "default-passive-events"
// 把echarts添加到vue实例中
Vue.prototype.$echarts = echarts;

import router from './router'

Vue.use(VueResource);
Vue.use(ElementUI);

// 判断有没有登录
/* if(localStorage.token){
    // 登录成功
    // 设置token请求头
    Vue.http.headers.common['Authorization'] = localStorage.token
}else{
  //  登录失败
  location.href = './login.html'
} */

// resource 拦截器

Vue.http.interceptors.push((result,next)=>{
       if(localStorage.token){
            // 登录成功
            // 设置token请求头
            Vue.http.headers.common['Authorization'] = localStorage.token
       }else{
            //登录失败 
            location.href='./login.html'
       };
       next((response)=>{
              if(response.status == 401){
                   location.href='./login.html'
              }else if( response.status == 404){
                    this.$message.error("请检查网络是否连接");
              }
       })
})

new Vue({
  el: '#app',
  store,
  router,
  render: h => h(App)
})
